//
//  FileManager.swift
//  Raptor
//
//  Created by Jason on 2023/8/22.
//  Copyright © 2023 IMS. All rights reserved.
//

import Foundation

// MARK: - 接口

//enum FileAPI {
//    
//    case uploadImg(files: [UIImage], acceptImageDataKey: String, params: [String : Any]? = nil)
//    case fileUpload(files: [URL], acceptImageDataKey: String, params:[String : Any]? = nil)
//    case fileDownload(filePath: String, fileName: String)
//    
//    // 获取想要存储的文件路径
//    var localLocation: URL {
//        switch self {
//            
//        case .fileDownload(let filePath, let fileName):
//            var documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
//            documentsURL.appendPathComponent(filePath + fileName)
//            return documentsURL
//        default:
//            return URL(string: "")!
//        }
//    }
//    // 封装下下载路径
//    var downloadDestination: DownloadDestination {
//        // `createIntermediateDirectories` will create directories in file path
//        return { _, _ in return (self.localLocation, [.removePreviousFile, .createIntermediateDirectories]) }
//    }
//    
//}
//
//extension FileAPI: TargetType {
//    // 主域
//    var baseURL: URL {
//        var urlString: String = baseMiddlewareDomain(enviroment: NetworkManager.enviroment)
//        if let domain: String = AppManager.shared().selectedOrg?.salesforceDomain {
//            urlString = domain
//        }
//        
//        switch self {
//            //        case .queryTowerStructure(parameters: _):
//            //            guard let url = URL(string: urlString + kServicesMobilePrefix + kAPIMethodName_queryTowerStructure) else { fatalError("BaseURL could not be configured.") }
//            //            return url
//        case .uploadImg(files: _, acceptImageDataKey: _, params: _):
//            <#code#>
//        case .fileUpload(files: _, acceptImageDataKey: _, params: _):
//            <#code#>
//        case .fileDownload(filePath: _, fileName: _):
//            <#code#>
//        }
//        
//    }
//    
//    // 请求路径
//    var path: String {
//        return ""
//    }
//    
//    // 公共请求头
//    var headers: [String: String]? {
//        return NetworkManager.getHeaders(true)
//    }
//    
//    // 请求方式
//    var method: Moya.Method {
//        switch self {
//            //        case .queryTowerStructure(parameters: _):
//            //            guard let url = URL(string: urlString + kServicesMobilePrefix + kAPIMethodName_queryTowerStructure) else { fatalError("BaseURL could not be configured.") }
//            //            return url
//        case .uploadImg(files: _, acceptImageDataKey: _, params: _):
//            return .post
//        case .fileUpload(files: _, acceptImageDataKey: _, params: _):
//            return .post
//        case .fileDownload(filePath:_, fileName: _):
//            return .get
//        }
//    }
//    
//    // 解析格式
//    var sampleData: Data {
////                URLEncoding.default
//        return "{}".data(using: String.Encoding.utf8)!
//    }
//    
//    var task: Task {
//        // 公共请求参数
//        //        var params = NetworkManager.getGlobalRequestParams()
//        switch self {
//        case let .uploadImg(fileArray, acceptImageDataKey, params):
//            var formDatas = [MultipartFormData]()
//            let formatter = DateFormatter()
//            for i in 0..<fileArray.count {
//                let image = fileArray[i]
//                let imageData = image.jpegData(compressionQuality: 0.5)
//                formatter.dateFormat = "yyyyMMddHHmmss"
//                let timeStr = formatter.string(from: Date())
//                let fileName = "\(timeStr)+\(i).png"
//                DebugLog("\(fileName)")
//                //                    multipartFormData.append(imageData!, withName: acceptImageDataKey, fileName: fileName, mimeType: "image/png")
//                if imageData != nil {
//                    let formData = MultipartFormData(provider: .data(imageData!), name: acceptImageDataKey, fileName: fileName, mimeType: "image/png")
//                    formDatas.append(formData)
//                }
//            }
//            return .uploadCompositeMultipart(formDatas, urlParameters: params ?? [String: Any]())
//        case let .fileUpload(fileUrls, name, params):
//            var formDatas = [MultipartFormData]()
//            for url in fileUrls {
//                do {
//                    let data = try Data(contentsOf: url, options: .alwaysMapped)
//                    let fileName = url.lastPathComponent
//                    let formData = MultipartFormData(provider: .data(data), name: name, fileName: fileName, mimeType: "multipart/form-data")
//                    formDatas.append(formData)
//                } catch{
//                    print("文件拼接失败")
//                }
//            }
//            return .uploadCompositeMultipart(formDatas, urlParameters: params ?? [String: Any]())
//        case .fileDownload:
//            return .downloadDestination(downloadDestination)
//            
//        }
//        
//    }
//    
//}
//
///// <#Description#>
//class AppFileManager: NSObject {
//    
//    static let provider: MoyaProvider<FileAPI> = MoyaProvider<FileAPI>(plugins: [
//        NetworkTimeoutPlugin(),
//    ])
//    
//    /// 下载文件
//    /// - Parameters:
//    ///   - filePath: 文件夹名称
//    ///   - fileName: 文件名称
//    ///   - completion: 回调
//   @objc static func downLoad(filePath: String, fileName: String,progressBlock:((Double) -> ())?, completion: @escaping (ResponseBasicInformation) -> Void) {
//        provider.imsRequest(FileAPI.fileDownload(filePath: filePath, fileName: fileName),progress: { progress in
//            print("当前进度: \(progress.progress)")
//            if let progressBlock = progressBlock {
//                progressBlock(progress.progress)
//            }
//        }, completionCallBack: completion)
//    }
//    
//    /// 上传图片
//    /// - Parameters:
//    ///   - files: [UIImage]
//    ///   - acceptImageDataKey: 服务端对应接受的key
//    ///   - completion: 回调
//    @objc static func uploadImage(files: [UIImage], acceptImageDataKey: String, params: [String : Any]? = nil, completion: @escaping (ResponseBasicInformation) -> Void) {
//        provider.imsRequest(FileAPI.uploadImg(files: files, acceptImageDataKey: acceptImageDataKey, params: params), completionCallBack: completion)
//    }
//    
//    // 上传文件
//    // - Parameters:
//    //   - files: [UIImage]
//    //   - acceptImageDataKey: 服务端对应接受的key
//    //   - completion: 回调
//    @objc static func fileUpload(files: [URL], acceptImageDataKey: String, params: [String : Any]? = nil, completion: @escaping (ResponseBasicInformation) -> Void) {
//           provider.imsRequest(FileAPI.fileUpload(files: files, acceptImageDataKey: acceptImageDataKey, params: params), completionCallBack: completion)
//        }
//}
